//************************************************************************
/// <copyrigth>2024-2025 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Cross-Platform thread-based timer
///</describe>
/// <date>2024/3/9</date>
///***********************************************************************
#ifndef TIMER_H
#define TIMER_H

#include <functional>
#include <memory>
#include "ModuleLoader/ModuleConfig.h"

namespace SystemTool
{
    enum CLASS_ITEM TimerPriority
    {
        TIMER_LOWEST = 0,
        TIMER_LOW,
        TIMER_NORMAL,
        TIMER_HIGH,
        TIMER_HIGHEST
    };

    class CLASS_ITEM Timer
    {
    public:
        // Construct the timer with interval
        Timer(long iPeriodInterval, long iDelayTimeAndStart = 0);

        // Destruct the timer
        ~Timer();
    
    private:
        // Copy construct
        Timer(const Timer &other) = delete;

        // Assigment
        Timer &operator=(const Timer &other) = delete;

    public:
        // Start with callback func and priority
        void Start(std::function<void(void *)> fFunc, void *pUserData, TimerPriority ePreority = TIMER_NORMAL);

        // Stop the timer
        void Stop();

        // Stop the timer inner callback func
        void StopInCallBackFunc();

        // How many cnt has beened skipped
        long GetSkippedCnt() const;

        // Get current start interval
        long GetCurStartInterval() const;

        // Set start interval which will be effetived again before start()
        void SetStartInterval(long iMs);

        // Get current peroid interval
        long GetCurPeroidInterval() const;

        // Set peroid interval and it will be used by next peroid
        void SetPeroidInterval(long iMs);

    private:
        // Poco timer
        void* m_pTimer;

        // Callback
        void* m_pCallBack;
    };
}

#endif // TIMER_H
